﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace End_term
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("server=LAPTOP-94P4A8KT;uid=sa;pwd=123456;database=Blogs");

            SqlCommand cmd = new SqlCommand("select * from Users where Username='" 
                + textBox1.Text.Trim() + "' and Password='" + textBox2.Text.Trim() + "'", conn);

            if (textBox1.Text == "" || textBox2.Text == "")
                MessageBox.Show("提示：请输入用户名和密码");

            conn.Open();

            SqlDataReader sdr = cmd.ExecuteReader();
            sdr.Read();
            if (sdr.HasRows) 
            {
                MessageBox.Show("登录成功!");
                this.Hide();
                Mainform mainform = new Mainform();
                mainform.Show();
            }else
            {
                MessageBox.Show("用户名或密码错误!");
            }
            
            conn.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Register re = new Register();
            re.Show();
             
            
        }
    }
}
